package message

import (
	"encoding/hex"
	"hy_808/protocol/hygprs"
	"strings"
)

/*
+0	80 00 48 02 00 1e 84
+7	01 00 00 00 0c
+12	02 00 00 02 db
+17	03 20
+19	04 00 09 28 ce
+24	06 61 76 23 9f
+29	07 04 2f f2 67
+34	08 01 4f df 9a
+39	09 00 00 方向角
+42	0f 00 报警类型 超速
+44	0a 00 00 速度
+47	0c 15 站点号
+49	0b 01 上下行
+51	27 61 76 23 3b 车载端每组超速时产生的唯一标识
+56	28 00 3c 超速时的速度基准值
+59	29 00 14 超速时的时长基准值
+62	30 00 00 连续超速时长
+65	1a 01
+67	00 00 0b 18 81
+72
*/
/*
80 00 48 02 06 CB 84
01 00 00 00 34
02 00 00 00 6F
03 21
04 01 50 09 01
06 62 1D CB 50
07 04 27 E2 71
08 01 6F 25 EE
09 2C EC
0F 00
0A 00 6F 0C 00
0B 01
27 62 1D CB 50
28 00 00
29 00 05
30 00 08
1A 01
00 00 0C 23 81
*/
type Alarm struct {
	hygprs.Fields
}

func GenAlarm() Alarm {
	data, _ := hex.DecodeString(strings.ReplaceAll("80 00 48 02 09 FA 84 01 00 00 00 0A 02 00 00 03 FD 03 11 04 00 09 29 89 06 62 20 33 CB 07 04 23 29 04 08 01 5A 2A 5C 09 49 0C 0F 0F 0A 00 00 0C 13 0B 01 27 00 00 00 00 28 00 00 29 00 00 30 00 00 1A 01 00 00 08 6F 81", " ", ""))
	return Alarm{hygprs.MakeFields(hygprs.MakePacket(data))}
}

func (p Alarm) SetUnique(v uint32) {
	copy(p.Data[52:], hygprs.FromUint32(v))
}

func (p Alarm) SetSpeedLimit(v uint16) {
	copy(p.Data[57:], hygprs.FromUint16(v))
}

func (p Alarm) SetDurationLimit(v uint16) {
	copy(p.Data[60:], hygprs.FromUint16(v))
}

func (p Alarm) SetDuration(v uint16) {
	copy(p.Data[63:], hygprs.FromUint16(v))
}
